#!/usr/bin/env python
# -*-coding:UTF-8 -*-
'''
@Project ：爬虫-波波老师
@File：14-xpath58二手.py
@Author ：文非
@Date：2021/3/1115:29
@Require： 需求爬取58二手房中的房源信息
'''

import requests
from lxml import etree
if __name__ == "__main__":
    # UA伪装
    headers = {
        'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36"
    }
    # 配置url
    url = "https://map.tianditu.gov.cn/api/services?mn=GetServerListByPage&isShown=1&toTime=&keyname=serviceindex&keywords=&isTop=1&pageSize=12&state=1&searchText=&fromTime=&pageNum=1&sort=desc&isAvailable="
    # 发送get请求 获取响应数据
    page = requests.get(url=url, headers=headers).text # 先获取整个页面的数据
    # 实例化etree对象
    tree = etree.HTML(page)
    print(page)
    list_data = tree.xpath('//div[@class="kvov objProp"][3]')
    print(list_data)
    # fp = open("./58ershou.txt","w",encoding="utf-8")
    # for list in list_data:
    #     title = list
    #     print(title)
    #     fp.write(title+"\n")
    print("************* 爬取 结束 **************")

#
#
#!/usr/bin/env python
# -*-coding:UTF-8 -*-
'''
@Project ：19-xpath站长素材.py
@File：45-selenium_药监局.py
@Author ：文非
@Date：2021/3/1615:26
@Require：# 网页自动化程序初始
'''

from selenium import webdriver
from lxml import etree
from time import sleep
# 实例化一个浏览器对象 传入浏览器的驱动程序
brows = webdriver.Chrome(executable_path="C:\Program Files\Google\Chrome\Application\chromedriver.exe")
# 编写基于浏览器自动化的操作代码

# 使用selenium 爬取动态加载的数据药监局 http://scxk.nmpa.gov.cn:81/xk/itownet/portalAction.do?method=getXkzsList
# 让浏览器发起一个指定url的对应请求

# url = 'https://map.tianditu.gov.cn/'
# brows.get(url)
# time.sleep(2)
# brows.find_element_by_xpath('//div[@class="ThematicLayer_head__1MXVk"]/button').click()
# handle = brows.current_window_handle
# brows.switch_to_window(handle)
# data = brows.find_element_by_xpath('//div[@class="ServiceResource_sourcesList__2Rwcf"]//li//span//text()')
# num=0
# for page in range(1,380):
#     # 获取浏览器当前页面源码数据
#     page_text = brows.page_source  # page_source属性返回的是页面源码数据
#     # print(page_text)
#     tree = etree.HTML(page_text)
#     li_list = tree.xpath('///ul[@id="gzlist"]/li')
#
#     for li in li_list:
#         name = li.xpath('./dl/@title')[0]
#         print(name)
#     num = num+1
#     print('""""""""第""""'+str(num)+"""""数据""")
# sleep(5)
# brows.quit()